﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 属性
{
    class Program
    {
        static void Main(string[] args)
        {
            Person p1 = new Person();
            p1.Age = 18;
            Console.WriteLine("我的年龄是{0}", p1.Age);
        }
    }

    class Person
    {
        private int age;
        public int Age    //属性
        {
            set  //赋值
            {
                if (value < 0)
                {
                    return;
                }
                this.age = value;   //value就代表用户传过来的值
                //这里不能写this.Age = value,否则死循环，这点经常错
            }
            get  //取值
            {
                return this.age;
            }
        }
    }
}
